package edu.cuc.akkaDay01.demo02;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.japi.pf.ReceiveBuilder;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;

/**
 * Created by bingruiqi on 2017/9/10.
 */
public class HelloWorld extends AbstractActor {
    ActorRef greeter;
    @Override
    public void preStart() throws Exception {
        greeter = context().actorOf(Props.create(Greeter.class), "greeter");
        System.out.println("Greeter Actor Path" + greeter.path());
        greeter.tell(Greeter.Msg.GREETER,self());
    }

    @Override
    public PartialFunction<Object, BoxedUnit> receive() {
        return ReceiveBuilder.matchEquals(Greeter.Msg.DONE,o->{
            sender().tell(Greeter.Msg.GREETER,self());
            context().stop(self());
        }).build();
    }
}
